import time

class HandlerBase:
    def __init__(self, serial_manager):
        self.serial_manager = serial_manager

    def handle(self, command):
        """
        处理指令
        :param command: 指令字典
        :return: 响应字典
        """
        raise NotImplementedError("子类必须实现 handle 方法")

    def build_response(self, cmd, is_set_power, is_set_timing, is_ignore_locktime, timeout=5):
        """
        构建响应字典
        :param cmd: 指令名称
        :param is_set_power: 是否设置电源
        :param is_set_timing: 是否设置定时
        :param is_ignore_locktime: 是否忽略锁定时间
        :param timeout: 超时时间
        :return: 响应字典
        """
        return {
            "cmd": cmd.upper(),
            "is_set_power": is_set_power,
            "is_set_timing": is_set_timing,
            "is_ignore_locktime": is_ignore_locktime,
            "timestamp": int(time.time()),
            "timeout": timeout
        }